def binary_search(num_list, x):
    '''
    二分查找
    '''
    left ,right = 0, len(nums)-1
    if target > nums[right]:
        return right+1

    while right > left:
        mid = (right+left)//2
        if target == nums[mid]:
            return mid
        elif target > nums[mid]:
            left = mid+1 #这里的边界条件很重要
        elif target < nums[mid]: 
            right = mid
            
    return left # 当right==left 结束


if __name__ == '__main__':
    num_list = [34, 6, 78, 9, 23, 56, 177, 33, 2, 6, 30, 99, 83, 17]
    print(sorted(num_list), len(num_list))
    print(binary_search(num_list, 34))
    print(binary_search(num_list, 177))
